package com.toread.platform.hystrix;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.util.Random;

/**
 * Created by toread on 17-8-11.
 */
@Component
public class CallDependencyService {
    private static final Logger logger = LoggerFactory.getLogger(CallDependencyService.class);

    @Autowired
    private RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "fallback")
    public String say() {
        logger.info("CallDependencyService测试");
        return restTemplate.getForEntity("http://PROVIDER-SERVICE/say",String.class).getBody();
    }

    public String fallback(){
        return "some exception occur call fallback method.";
    }
}
